<template>
  <div class="shop_ticket_details">
    <el-radio-group style="margin: 10px 0;" v-model="radio" @change="changeType">
      <el-radio :label="0">类型不限</el-radio>
      <el-radio :label="1">商户购买</el-radio>
      <el-radio :label="2">平台发放</el-radio>
    </el-radio-group>

    <el-table :data="recordData" border>
      <el-table-column label="停车券" align="center">
        <template slot-scope="scope">
          {{scope.row.parkingDuration}}小时{{scope.row.sellPrice}}元，有效期{{scope.row.validityDays}}天
        </template>
      </el-table-column>
      <el-table-column label="数量" prop="quantity" align="center"></el-table-column>
      <el-table-column label="支付金额" prop="paidAmount" align="center"></el-table-column>
      <el-table-column label="类型" align="center">
        <template slot-scope="scope">
          {{scope.row.fromType | fromTypeFilter}}
        </template>
      </el-table-column>
      <el-table-column label="发放购买时间" prop="createTime" align="center"></el-table-column>
    </el-table>

    <el-pagination
      :current-page="searchForm.currentPage"
      :page-sizes="[10, 15, 20, 30]"
      :page-size="searchForm.pageSize"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      align="center"
      style="margin-top:10px;"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />



  </div>
</template>

<script>
  export default {
    props: ['id'],
    filters: {
      fromTypeFilter(type) {
        return type == 1 ? '商户购买' : '平台发放'
      }
    },
    data() {
      return {
        searchForm: {
          currentPage: 1,
          pageSize: 10
        },
        recordData: [],
        total: 0,
        radio: 0
      }
    },

    mounted() {
      this.searchForm.shopId = this.id;
      this.getTicketRecord();
    },

    methods: {
      getTicketRecord() {
        this.$axios({
          method: 'get',
          url: '/shop/park-ticket-buy-record/page',
          params: this.searchForm
        }).then((res) => {
          if(res.code == 200) {
            this.recordData = res.data.records;
            this.total = res.data.total;
          }
        })
      },

      changeType(e) {
        this.searchForm.fromType = e;
        this.getTicketRecord();
      },

      // 分页修改每页显示条数
      handleSizeChange(val) {
        this.searchForm.pageSize = val;
        this.getTicketRecord();
      },
      // 分页跳转页面
      handleCurrentChange(val) {
        this.searchForm.currentPage = val;
        this.getTicketRecord();
      }
    }
  }
</script>

<style scoped>






</style>
